package com.baidb.gateway.ribbon.configuration;

import com.baidb.gateway.properties.GrayProperties;
import com.baidb.gateway.ribbon.filter.GrayLoadBalancerClientFilter;
import com.baidb.gateway.ribbon.rule.RibbonServerDiscoveryRule;
import com.netflix.loadbalancer.IRule;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.config.LoadBalancerProperties;
import org.springframework.cloud.gateway.filter.LoadBalancerClientFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author baidb
 * @date 2021/6/17.
 */
@SuppressWarnings("deprecation")
@Configuration
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled", havingValue = "true")
public class RibbonConfiguration {

    @Bean
    public LoadBalancerClientFilter loadBalancerClientFilter(LoadBalancerClient client,
        LoadBalancerProperties properties, GrayProperties grayProperties) {
        return new GrayLoadBalancerClientFilter(client, properties, grayProperties);
    }

    @Bean
    public IRule ribbonRule() {
        return new RibbonServerDiscoveryRule();
    }

}
